package com.aaa.dao20220728.impl;

import com.aaa.dao20220728.DeptDao;
import com.aaa.utils.BaseDao;

import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/28 10:48
 * @description：部门dao接口实现类  针对mysql数据库的实现
 * @modified By：
 * @version: 1.0
 */
public class DeptDaoImpl extends BaseDao implements DeptDao {
    @Override
    public boolean saveDept(Map<String, Object> map) {
        String sql = "insert  into dept (dname,loc)  values(?,?)";
        return super.executeUpdate(sql, map.get("dname"), map.get("loc"));
    }

    @Override
    public boolean deleteDeptById(Integer deptno) {
        String sql = "delete from dept where deptno =?";
        return executeUpdate(sql, deptno);
    }

    @Override
    public boolean updateDept(Map<String, Object> map) {
        String sql = "update  dept set dname=? ,loc=? where deptno=?";
        return executeUpdate(sql, map.get("dname"), map.get("loc"), map.get("deptno"));
    }

    @Override
    public Map<String, Object> queryDeptById(Integer deptno) {
        String sql = "select * from dept where deptno=?";
        List<Map<String, Object>> mapList = executeQuery(sql, deptno);
        //判断非空
        if (null != mapList && mapList.size() > 0) {
            //直接返回第一条数据
            return mapList.get(0);
        }else{
            //没有数据
            return null;
        }

    }

    @Override
    public List<Map<String,Object>> queryAllDept() {
        return executeQuery("select * from dept");
    }
}
